package com.eaoa.uc.account.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.eaoa.base.EABaseAction;
import com.eaoa.uc.account.bo.AccountChangePasswordBO;
import com.stony.core.exception.RunException;

public class AccountChangePasswordAction extends EABaseAction{

	@Override
	protected ActionForward doWork(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String oldpassword = request.getParameter("oldpassword");
		String password = request.getParameter("password");
		String password2 = request.getParameter("password2");
		if(StringUtils.isBlank(oldpassword)){
			throw new RunException("errors.change.oldpassword");
		}if(StringUtils.isBlank(password) || StringUtils.isBlank(password2)
			||	!password.equals(password2)){
			throw new RunException("errors.change.newpassword");
		}
		
		Long accountno = getEmployee(request).getAccountno();
		new AccountChangePasswordBO(accountno, oldpassword ,  password, false).execute();

		return mapping.findForward("success");
	}
}
